package com.chw.controller;

import com.chw.common.ChwTS;
import com.chw.model.Brand;
import com.chw.model.Key;
import com.chw.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("brand")
public class BrandController {
    @Autowired
    private BrandService brandService;
    //查询
    @RequestMapping("queryBrand")
    public ChwTS queryBrand(Brand brand){
        try{

            return ChwTS.success(brandService.queryBrand(brand));
        }
        catch (Exception e){
            return  ChwTS.error(500,e.getMessage());
        }
    }
    @RequestMapping("updateBrand")
    public ChwTS updateBrand(Brand brand){
        try{
            if (brand.getId()==null){
                return ChwTS.error(400,"缺少参数");
            }
            brandService.updateBrand(brand);
            return ChwTS.success("");
        }
        catch (Exception e){
            return  ChwTS.error(500,e.getMessage());
        }
    }
    @RequestMapping("addBrand")
    public ChwTS addBrand(Brand brand){
        try{
            if (brand.getName()==null){
                return ChwTS.error(400,"缺少参数");
            }
            brandService.addBrand(brand);
            return ChwTS.success("");
        }
        catch (Exception e){
            return  ChwTS.error(500,e.getMessage());
        }
    }
    @RequestMapping("deleteBrand")
    public ChwTS deleteBrand(Integer id,Integer isDel){
        try{
            if (id==null){
                return ChwTS.error(400,"缺少参数");
            }
            brandService.deleteBrand(id,isDel);
            return ChwTS.success("");
        }
        catch (Exception e){
            return  ChwTS.error(500,e.getMessage());
        }
    }
}

